package com.design_pattern.Iterator;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * 迭代器模式
 * 适用 只读模式
 */

public class MyIterator implements Iterable<String> {
    private List<String> data = Arrays.asList("a", "b", "c");


    @Override
    public Iterator<String> iterator() {
        return new Ite();
    }

    public class Ite implements Iterator<String>{
        private int index = 0;
        @Override
        public boolean hasNext() {
            return index< data.size();
        }

        @Override
        public String next() {
            index++;
            return data.get(index);
        }
    }
}


